//
//  ImageInfoViewController.m
//  DianNaoWang
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ImageInfoViewController.h"
#import "Header.h"
#import "CFNetworkFromAFNetworking.h"
#import "ImageCollectionCell.h"
#import "UIImageView+WebCache.h"
@interface ImageInfoViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic, retain)NSMutableArray *dataSourceArray;
@property(nonatomic, retain)UICollectionView *collectionView;
@property(nonatomic, retain)UIImageView *leftImageView;
@end

@implementation ImageInfoViewController

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}

-(void)loadView
{
    [super loadView];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    self.view.backgroundColor = [UIColor blackColor];
    self.dataSourceArray = [NSMutableArray array];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getdata];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(ScreenWidth, 250 * FitHeight);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.sectionInset = UIEdgeInsetsMake(220 * FitHeight, 0, ScreenHeight - (250 + 220) * FitHeight, 0);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) collectionViewLayout:flowLayout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.pagingEnabled = YES;
    [self.view addSubview:_collectionView];
    //[_collectionView release];
    
    [_collectionView registerClass:[ImageCollectionCell class] forCellWithReuseIdentifier:@"cell"];
    
    
    self.leftImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 30, 30)];
    self.leftImageView.image = [[UIImage imageNamed:@"zuojiantou"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    _leftImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    [_leftImageView addGestureRecognizer:tap];
    [self.view addSubview:_leftImageView];
    
}

-(void)tapAction{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark - collection的样式
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataSourceArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ImageCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:_dataSourceArray[indexPath.row]] placeholderImage:[UIImage imageNamed:@"123"]];
    return cell;
}



#pragma mark - 获取数据 是一个图片网址的数组
- (void)getdata
{
    NSString *urlString = [NSString stringWithFormat:@"http://lib.wap.zol.com.cn/ipj/picToursPro/?v=1.0&pro_id=%@&size=640x960",_Id];
    [CFNetworkFromAFNetworking askObjectByURLString:urlString BodyString:nil WithObjectBlock:^(id object) {
        NSArray *array = [object objectForKey:@"list"];
        for (NSDictionary *dic in array) {
            [self.dataSourceArray addObject:[dic objectForKey:@"images_src"]];
        }
       // //NSLog(@"%@", _dataSourceArray[0]);
        [_collectionView reloadData];
    }];
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
